package tt.dz.appserver.dao.ext;

import java.util.List;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import tt.dz.appserver.dao.base.BasisDao;
import tt.dz.appserver.entity.model.pub.Shares;
import tt.dz.appserver.util.Constants;

@Repository
public class SharesDao extends BasisDao<Shares> {

	/**
	 * 获取分享列表
	 * 
	 * @param pageNo
	 * @return
	 */
	@Cacheable(value="shares",key="'pageNo'+#pageNo")
	public List<Shares> findSharesList(Integer pageNo) {

		Shares shares = new Shares();
		shares.setValid_flag(1);
		return super.findExample(shares, pageNo, Constants.PAGE_SIZE, "share_time", 0);
	}
	
	/**
	 * 根据用户Id获取分享列表
	 * 
	 * @param pageNo
	 * @return
	 */
	@Cacheable(value="shares",key="'userId'+#userId+'pageNo'+#pageNo")
	public List<Shares> findSharesList(String userId, Integer pageNo) {

		Shares shares = new Shares();
		shares.setValid_flag(1);
		shares.setUser_id(userId);
		return super.findExample(shares, pageNo, Constants.PAGE_SIZE, "share_time", 0);
	}

	/**
	 * 获取分享详细
	 * @param shareId
	 * @return
	 */
	@Cacheable(value="shares",key="'shareId'+#shareId")
	public Shares findSharesDetailByShareId(String shareId){

		Shares shares = new Shares();
		shares.setValid_flag(1);
		shares.setShare_id(shareId);
		List<Shares> sharesList = super.findExample(shares);
		
		if(sharesList.size()>0){
			return sharesList.get(0);
		}
		return null;
	}

	/**
	 * 保存桩友圈
	 * @param share
	 * @return
	 */
	@CacheEvict(value="shares",allEntries=true)
	public int save(Shares obj) {
		return super.save(obj);
	}

	/**
	 * 逻辑删除
	 */
	@CacheEvict(value="shares",allEntries=true)
	public int LogicDelete(Shares obj) {
		return super.LogicDelete(obj);
	}
	
}




